home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / prospero / PRM / src / testprog / bcast.c next >
Encoding:
C/C++ Source or Header  |  1993-04-24  |  2.1 KB  |  97 lines

  1. /*
  2.  * Copyright (c) 1992, 1993 by the University of Southern California
  3.  *
  4.  * For copying and distribution information, please see the files
  5.  * <prm-copyr.h>.
  6.  */
  7.  
  8. #include <prm-copyr.h>
  9.  
  10.  
  11. #include <stdio.h>
  12. #include <sys/time.h>
  13. #include <sys/resource.h>
  14. #include <sys/times.h>
  15.  
  16. #define  MAIN_PROG
  17. #include <comm.h>   /*     This file defines certain constants, and declares
  18.             some global variables used by the message passing
  19.             routines.  */
  20.  
  21. #ifdef HPUX
  22. #   define srandom srand
  23. #   define random rand
  24. #endif
  25.  
  26. #ifndef NUM_ITER 
  27. #  define NUM_ITER 500
  28. #endif
  29.  
  30. #ifndef ASIZE
  31. #  define ASIZE 4
  32. #endif
  33.  
  34.  
  35. #ifndef RNEIGH
  36. #   define RNEIGH(x,tot)    (x<tot)?x+1:1 /* right neighbor of x in the ring */
  37. #endif
  38.  
  39. float a[ASIZE];
  40.  
  41. char *progname;
  42.  
  43. main(argc, argv)
  44. int argc;
  45. char **argv;
  46. {
  47.   int i, j, ntasks, my_tid;
  48.   int time_dcrmt, timeleft, iter_cnt, nbytes;
  49.   int sendto_task;
  50.   double time;
  51.   char fname[32];
  52.   struct rusage rusage1, rusage2;
  53.   FILE *fd;
  54.  
  55.   init_task(argv);    /* Initialization is required for all tasks in every
  56.              application */
  57.  
  58.   nbytes = ASIZE * sizeof(float);
  59.   pfs_debug=0;
  60.   my_tid = gettid(); 
  61.   if (my_tid == -1) {
  62.     io_printf(" task could not get its tid!", (char *)0);
  63.     exit(1);
  64.   }
  65.   
  66.   ntasks = numtasks();   /* Total number of tasks in this job */
  67.   
  68.   if ( my_tid == 1 ) {
  69.     getrusage(RUSAGE_SELF, &rusage1);
  70.     
  71.     for (iter_cnt = 1; iter_cnt <= NUM_ITER; iter_cnt++) {
  72.       CMMD_bc_to_nodes(a, nbytes);
  73.     }
  74.     getrusage(RUSAGE_SELF, &rusage2);
  75.     time = (double) ((rusage2.ru_utime.tv_sec - rusage1.ru_utime.tv_sec) +
  76.              (rusage2.ru_stime.tv_sec - rusage1.ru_stime.tv_sec) ) +
  77.                ((double)((rusage2.ru_utime.tv_usec - rusage1.ru_utime.tv_usec) +
  78.                  (rusage2.ru_stime.tv_usec - rusage1.ru_stime.tv_usec)) 
  79.             ) / 1.0E+6;
  80.     sprintf(fname, "bcast_timings_%d", nbytes);
  81.     fd = fopen(fname, "a");
  82.     fprintf(fd, "%d\t %d\t %f \n", NUM_ITER, ntasks, time);
  83.     fclose(fd);
  84.   }
  85.  
  86.   else {
  87.     for (iter_cnt = 1; iter_cnt <= NUM_ITER; iter_cnt++) 
  88.     CMMD_receive_bc_from_node(a, nbytes);
  89.     
  90.   }
  91.  
  92.   io_printf("task %d done.\n", my_tid, (char *)0 );
  93.   
  94.   exit(0);
  95. }
  96.  
  97.